package com.jinzhi.jzweb.controller;

import com.jinzhi.jzweb.domain.JazBedNumberDO;
import com.jinzhi.jzweb.domain.JazHouseTypesDO;
import com.jinzhi.jzweb.domain.JazQuestionDO;
import com.jinzhi.jzweb.service.JazHouseTypesService;
import com.jinzhi.jzweb.service.JazQuestionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/jzweb/house")
public class JazHouseListController {
    @Autowired
    private JazQuestionService jazQuestionService;

    @Autowired
    private JazHouseTypesService jazHouseTypesService;

    @GetMapping()
    @RequiresPermissions("jzweb:houseList:houseList")
    String JazHouseList(){
        return "jzweb/house/index";
    }

    @GetMapping("/info/{type}/{id}")
    String JazGroupSpecsInfo(@PathVariable("id") Long id,@PathVariable("type") String type,Model model){
        JazHouseTypesDO JazQuestiondo = null;
        List<JazBedNumberDO> doList=null;
        List<JazBedNumberDO> oldList=null;
        if(!type.equals("add")){
            JazQuestiondo=jazHouseTypesService.selectById(id);
            doList = jazHouseTypesService.selBedNumberList(id);
            oldList = jazHouseTypesService.selBedNumberListZoo(id);
        }
        model.addAttribute("id", id);
        model.addAttribute("myData", JazQuestiondo);
        model.addAttribute("doList", doList);
        model.addAttribute("oldList", null==oldList?"":oldList.stream().map(JazBedNumberDO::getCode).collect(Collectors.joining(",")).toString());
        model.addAttribute("type", type);
        return "jzweb/house/info";
    }
}




